home *** CD-ROM | disk | FTP | other *** search
- Path: tbj.dec.com!diamond
- From: diamond@tbj.dec.com (Norman Diamond)
- Newsgroups: comp.std.c
- Subject: Re: va_list, function calls.
- Date: 12 Apr 1996 03:54:08 GMT
- Organization: Digital Equipment Corporation Japan , Tokyo
- Message-ID: <4kkk50$h94@usenet.pa.dec.com>
- References: <4kdk5v$mn@solutions.solon.com>
- Reply-To: diamond@tbj.dec.com (Norman Diamond)
- NNTP-Posting-Host: jit533.tbj.dec.com
-
- In article <4kdk5v$mn@solutions.solon.com>, seebs@solutions.solon.com (Peter Seebach) writes:
- > void foo(int bar, ...) {
- > va_list ap;
- > int i;
- > va_start(ap, bar);
- > for (i = 0; i < bar; ++i)
- > baz(&ap);
- > va_end(ap);
- > }
- > void baz(va_list *ap) { printf("%d\n", va_arg(*ap)); }
- >is this legal? If not, is there a compelling reason?
-
- ANSI Classic section 4.8, page 123 lines 12 to 15: "The object ap may be
- passed as an argument to another function; if that function invokes the
- va_arg macro with parameter ap, the value of ap in the calling function
- is indeterminate and shall be passed to the va_end macro prior to any
- further reference to ap."
-
- The standard does not quite say that &ap may be passed, but let's try to
- pretend that this was an editorial oversight and a TC will permit it.
-
- After the first invocation of baz() returns, the value of ap in the
- calling function is indeterminate. ap can be passed to va_end, and I
- think that &ap can probably be computed and passed around, but the value
- of ap is just as indeterminate in the second invocation of baz() as it
- was in main() between the two invocations.
-
- What you really want is a TC to say that if &ap is passed then the value
- of ap does not become indeterminate. Ask your national representative to
- propose this.
- --
- << If this were the company's opinion, I would not be allowed to post it. >>
- "I paid money for this car, I pay taxes for vehicle registration and a driver's
- license, so I can drive in any lane I want, and no innocent victim gets to call
- the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
-